Generalize the "comX, X>=10" fix for all the Windows code.
authorrobertl <robertl>
Fri, 30 Jun 2006 04:41:15 +0000 (04:41 +0000)
committerrobertl <robertl>
Fri, 30 Jun 2006 04:41:15 +0000 (04:41 +0000)
Let the Magellan track reader NOT merge tracks across files.
Magellan track reader names tracks after file read.

defs.h
gbser.h
gbser_win.c
jeeps/gpsserial.c
magproto.c
reference/track/tracks.gpx

diff --git a/defs.h b/defs.h
index e7b23d4817677aaca52be71670f98d63d8f2acdf..7987a6b3a0eae788640d93eb01150a7b69ab50ba 100644 (file)
--- a/defs.h
+++ b/defs.h
 #  define _CRT_SECURE_NO_DEPRECATE 1
 #endif
 
+/* Pathname separator character */
+#if __WIN32__
+#  define GB_PATHSEP '\\'
+#else
+#  define GB_PATHSEP '/'
+#endif
+
 /* 
  *  Toss in some GNU C-specific voodoo for checking.
  */
diff --git a/gbser.h b/gbser.h
index ea6be83eba03192c217c994f0033bc2a4267bdac..44cf3f787af4418691306a3d6b2d7872a2634047 100644 (file)
--- a/gbser.h
+++ b/gbser.h
@@ -23,3 +23,7 @@ void *gbser_init(const char *name);
 void gbser_deinit (void *);
 int  gbser_read(void *handle, char *ibuf, int sz);
 int  gbser_setspeed(void *handle, unsigned speed);
+
+#if __WIN32__
+char * fix_win_serial_name(const char *comname);
+#endif
index b26db2c99a0a2adb3ae713339e341a6d013b28fd..c113614ff0b9c8fd9781dd7a1071ba149c00e560 100644 (file)
@@ -36,16 +36,17 @@ gbser_init(const char *portname)
 //     DCB tio;        
        COMMTIMEOUTS timeout;
        HANDLE comport;
-       char *xname= xstrdup("\\\\.\\\\");
+//     char *xname= xstrdup("\\\\.\\\\");
+       char *xname = fix_win_serial_name(portname);
        gbser_win_handle* handle = xcalloc(1, sizeof(*handle));;
 
-       /* Amazingly, windows will fail the open below unless we
-        * prepend \\.\ to the name.   It also then fails the open
-        * unless we strip the colon from the name.  Aaaaargh!
-        */
-       xname = xstrappend(xname, portname);
-       if (xname[strlen(xname)-1] == ':')
-               xname[strlen(xname)-1] = 0;
+//     /* Amazingly, windows will fail the open below unless we
+//      * prepend \\.\ to the name.   It also then fails the open
+//      * unless we strip the colon from the name.  Aaaaargh!
+//      */
+//     xname = xstrappend(xname, portname);
+//     if (xname[strlen(xname)-1] == ':')
+//             xname[strlen(xname)-1] = 0;
 //     xCloseHandle(comport);
 
        comport = CreateFile(xname, GENERIC_READ|GENERIC_WRITE, 
@@ -176,3 +177,36 @@ gbser_deinit(void *handle)
        gbser_win_handle *h = (gbser_win_handle *) handle;
        xfree(h);
 }
+
+
+
+
+/*
+ * This isn't part of the above abstraction; it's just a helper for 
+ * the other serial modules in the tree.
+ *
+ * Windows does a weird thing with serial ports.  
+ * COM ports 1 - 9 are "COM1:" through "COM9:"
+ * The one after that is \\.\\com10 - this function tries to plaster over
+ * that.
+ * It returns a pointer to a staticly allocated buffer and is therefore not
+ * thread safe.   The buffer pointed to remains valid only until the next
+ * call to this function.
+ */
+static char gb_com_buffer[100];
+
+char *
+fix_win_serial_name(const char *comname)
+{
+       /* If in the form 'COMx:', use it in place */
+       if ((strlen(comname) == 5) && (comname[4] == ':')) {
+               strcpy(gb_com_buffer, comname);
+       } else {
+               snprintf(gb_com_buffer, sizeof(gb_com_buffer),
+                       "\\\\.\\\\%s", comname);
+               if (gb_com_buffer[strlen(gb_com_buffer) - 1 ] == ':') {
+                       gb_com_buffer[strlen(gb_com_buffer) - 1] = 0;
+               }
+       }
+       return gb_com_buffer;
+}
index 543766dd22932ccad93de90bd53c81c14245046c..53dc1e62c576bb0499dad0fba6a8e1454e1f45ca 100644 (file)
@@ -88,14 +88,15 @@ int32 GPS_Serial_On(const char *port, gpsdevh **dh)
        DCB tio;
        COMMTIMEOUTS timeout;
        HANDLE comport;
+       char *xname = fix_win_serial_name(port);
        win_serial_data *wsd = xcalloc(sizeof (win_serial_data), 1);
        *dh = (gpsdevh*) wsd;
 
-       comport = CreateFile(port, GENERIC_READ|GENERIC_WRITE, 0, NULL,
+       comport = CreateFile(xname, GENERIC_READ|GENERIC_WRITE, 0, NULL,
                                          OPEN_EXISTING, 0, NULL);
 
        if (comport == INVALID_HANDLE_VALUE) {
-               GPS_Serial_Error("CreateFile on '%s' failed", port);
+               GPS_Serial_Error("CreateFile on '%s' failed", xname);
                gps_errno = SERIAL_ERROR;
                return 0;
        }
index b213655584a78d00e56eb299f84e1934e26c577c..1c5e6a317108af2cbd80f7f0c2b19eba19a116ac 100644 (file)
@@ -48,6 +48,7 @@ static char *nukewpt = NULL;
 static int route_out_count;
 static int waypoint_read_count;
 static int wpt_len = 8;
+static const char *curfname;
 
 typedef enum {
        mrs_handoff = 0,
@@ -467,6 +468,24 @@ retry:
                 */
                if (trk_head == NULL) {
                        trk_head = route_head_alloc();
+                       /* These tracks don't have names, so derive one
+                        * from input filename.
+                        */
+                       const char *s = strrchr(curfname, GB_PATHSEP);
+                       char *e;
+                       if (s) {
+                               s++; /* Skip path delim */
+                       }  else {
+                               s = curfname;/* use name intact */
+                       }
+
+                       /* Whack trailing extension if present. */
+                       trk_head->rte_name = xstrdup(s);
+                       e = strrchr(trk_head->rte_name, '.');
+                       if (e) {
+                               *e = '\0';
+                       }
+                       
                        track_add_head(trk_head);
                }
 
@@ -525,14 +544,15 @@ int
 terminit(const char *portname, int create_ok)
 {
        DCB tio;        
-       char *xname = xstrdup("\\\\.\\\\");
+//     char *xname = xstrdup("\\\\.\\\\");
+       char *xname = fix_win_serial_name(portname);
        COMMTIMEOUTS timeout;
 
     is_file = 0;
 
-       xname = xstrappend(xname, portname);
-       if (xname[strlen(xname)-1] == ':')
-               xname[strlen(xname)-1] = 0;
+//     xname = xstrappend(xname, portname);
+//     if (xname[strlen(xname)-1] == ':')
+//             xname[strlen(xname)-1] = 0;
 
        xCloseHandle(comport);
 
@@ -751,6 +771,7 @@ mag_rd_init_common(const char *portname)
 {
        time_t now, later;
        waypoint_read_count = 0;
+       curfname = portname;
 
        if (bs) {
                bitrate=atoi(bs);
@@ -908,6 +929,8 @@ mag_deinit(void)
                mkshort_del_handle(&mkshort_handle);
 
        waypt_flush(&rte_wpt_tmp);
+
+       trk_head = NULL;
 }
 
 
index c606cd4148e21b97eb9b4baef3ea5e94303fcff0..55dd187713dfa27417581ef1015ec1c8b9e9fc45 100644 (file)
@@ -7,6 +7,7 @@ xmlns="http://www.topografix.com/GPX/1/0"
 xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
 <time>2004-01-08T20:11:32Z</time>
 <trk>
+<name>meridian</name>
 <trkseg>
 <trkpt lat="30.062183333" lon="-91.610350000">
 <ele>1.000000</ele>